package cn.gok.demo3.controller;


import cn.gok.demo3.mapper.StudentMapper;
import cn.gok.demo3.entity.Student;
import cn.gok.demo3.service.StudentService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xxxx
 * @since 2022-07-21
 */
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentMapper studentMapper;
    private StudentService studentService;
    @RequestMapping("/findAllStudent")
    public List<Student> findAllStudent(){
        return studentMapper.selectList(null);
    }

    @RequestMapping("/findStudentById")
    public Student findStudentById(@RequestParam int sid){
        return studentMapper.selectById(sid);
    }

    @RequestMapping("/findStudentLike")
    public List<Student> findStudentLike(@RequestParam("sname") String sname){
        QueryWrapper<Student> wrapper=new QueryWrapper<>();
        wrapper
                .like("sname",sname);
        return studentMapper.selectList(wrapper);
    }

    @RequestMapping("/findStudentPage")
    public List<Student> findStudentPage(){
        Page<Student> page=new Page<>(1,3);
        studentMapper.selectPage(page,null);
        return page.getRecords();
    }

    @RequestMapping("/add")
    public int add(@RequestBody Student student){
        return studentMapper.insert(student);
    }

    @RequestMapping("/update")
    public int update(@RequestBody Student student){
        return studentMapper.updateById(student);
    }

    @RequestMapping("/deleteById")
    public int deleteById(@RequestParam Long sid){
        return studentMapper.deleteById(sid);
    }

    @RequestMapping("/deleteByIds")
    public int deleteByIds(@RequestBody List<Long> arr){
        return studentMapper.deleteBatchIds(arr);
    }
}

